package com.gjintel.framework.log.service.impl;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gjintel.framework.log.dao.IMessageDao;
import com.gjintel.framework.log.model.TSysWarningLog;
import com.gjintel.framework.log.service.IMessageService;
import com.gjintel.framework.user.model.User;
import com.gjintel.sdk.base.dao.Page;
import com.gjintel.sdk.base.dao.Sort;
import com.gjintel.sdk.base.service.impl.BaseServiceImpl;

@Service("messageService")
public class MessageServiceImpl extends BaseServiceImpl implements IMessageService {

	@Autowired
	private IMessageDao messageDao;
	
	@Override
	public void save(TSysWarningLog warning) {
	}

	@Override
	public List<TSysWarningLog> findAllByIds(TSysWarningLog warningLog, Page page, Sort sort) {
		return messageDao.findAllByIds(warningLog,page,sort);
	}

	@Override
	public List<TSysWarningLog> getMessageList(TSysWarningLog warningLog,Page page,User u,java.sql.Date startTime,java.sql.Date endTime,Integer flag) {
		
		return messageDao.getMessageList(warningLog,page,u,startTime,endTime,flag);
	}

	@Override
	@Transactional
	public void readed(String ids) {
		String [] idStrings = ids.split(",");
		for(int i=0;i<idStrings.length;i++){
			TSysWarningLog log = this.get(TSysWarningLog.class, idStrings[i]);
			log.setReadFlag(1);
			this.saveOrUpdate(log);
		}
		
	}

	@Override
	public int getCountByReaderId(String readerId) {
		return this.messageDao.getCountByReaderId(readerId);
	}
}
